home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / modem / modem-hardware.frm.z / modem-hardware.frm
Encoding:
Text File  |  2002-06-12  |  9.3 KB  |  355 lines

  1. #!/usr/bin/perl5
  2. #
  3. # modem-hardware.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: modem-hardware.frm,v 1.30 1997/11/17 19:08:52 shotes Exp $
  21.  
  22. # The following actions are taken to reconfigure modem hardware:
  23. # - port turned "off" in /etc/inittab
  24. # - telinit q command issued to reinitialize port
  25. # - fix-modem configuration script is run
  26. # - Devices file is edited (for dial-out or both)
  27. # - device is given uucp ownership (for dial-out or both)
  28. # - action field of /etc/inittab is updated (for dial-in or both)
  29. #
  30. # To determine current modem configurations, the following steps
  31. # are taken:
  32. # - to determine mode, first check inittab file.  if status=off,
  33. #    assume dial-out, if status=on check for existing ACU line
  34. #    in /etc/uucp/Devices.  if line exists it is both, otherwise
  35. #    assume dial-in.  got that?                                
  36. # - for dial-out or dial-in/dial-out, existing "ACU" line with proper
  37. #    port label gives modem and speed.  for dial-in only, I know of
  38. #    no way to get modem or speed.
  39. #
  40. # Note: this script requires the existence of the file 
  41. # /usr/OnRamp/etc/modem.trans to operate correctly
  42.  
  43. require "/usr/OnRamp/lib/OnRamp.pm";
  44. require "/usr/OnRamp/lib/java.pm";
  45.  
  46. $confI = "/etc/inittab";
  47. $confD = "/etc/uucp/Devices";
  48. $translate = "/usr/OnRamp/etc/modem.trans";
  49. $dummy = "/etc/uucp/Devices.tmp";
  50. $myname = "modem-hardware.cgi";
  51. $help_page = "modem-hardware-help.html";
  52. $title = "Modem Configuration";
  53.  
  54. $js = "
  55. $js_standard
  56. $js_help
  57. ";
  58.  
  59. print "Content-type: text/html\n\n";
  60. &js_title_block($title, $js);
  61.  
  62. &get_fields;
  63.  
  64. &get_modemList;
  65.  
  66. $help = $document_root . $ENV{"SCRIPT_NAME"};
  67. $help =~ s/cgi$/hlp/;
  68. exec $help if ($fld{'help'} eq "Help");
  69.  
  70. if ($fld{'doit'} eq 'Ok') {
  71.     if ($fld{'enable1'} eq 'Yes') { 
  72.     &reconfigure(1);
  73.     $message = "Port 1 has been reconfigured.";
  74.     }
  75.     if ($fld{'enable2'} eq 'Yes') { 
  76.     &reconfigure(2);
  77.     $message .= "  Port 2 has been reconfigured."; 
  78.     }
  79.     if (!$message) { $message = qq|To reconfigure a given port, click "Yes"
  80.             for the appropriate port under "Reconfigure".|; }
  81. }
  82.  
  83. &getCurrentStatus;
  84.  
  85. if (-d "/etc/uucp") { &generic; }
  86. else {
  87.     &header_block($title);
  88.     print "<i>Modem software not installed.  Install subsystem
  89.         </i><b>eoe.sw.uucp</b><i> from the distribution CD.</i>";
  90. }
  91.  
  92. sub error {
  93.     &error_block($_[0]);
  94.     &generic;
  95.     exit 0;
  96. }
  97.  
  98. sub get_modemList {
  99.     open(IN,"< $translate");
  100.     while(<IN>) { 
  101.     @items = split(/:/);
  102.     push(@modemList,$items[1]);
  103.     }
  104.     close(IN);
  105. }
  106.  
  107. sub reconfigure {
  108.     $num = $_[0];
  109.  
  110.     $switch = "";
  111.     &turnOffPort($num);
  112.     system("/sbin/telinit", "q");
  113.     if ($fld{'dial_out'.$num} eq 'Yes') {
  114.     $switch = "o"; 
  115.     &editDevice($num);
  116.     $expr = "chown uucp /dev/ttyd" . $num;
  117.     eval($expr);
  118.     if ($fld{'speed'.$num} > 2400) { 
  119.         $expr = "chown uucp /dev/ttyf" . $num; 
  120.     } else { $expr = "chown uucp /dev/ttym" . $num; }
  121.     eval($expr);
  122.     } else { &deleteDevice($num); }
  123.     if ($fld{'dial_in'.$num} eq 'Yes') {
  124.     $switch = "i" . $switch;
  125.     &turnOnPort($num);
  126.     }
  127.     if ($switch) {
  128.         $cmd = &hash_modem($fld{'modem'.$num},1,3);
  129.         if ($cmd) {
  130.                 if ($switch ne "o") {
  131.                 @cmd = split(/\s+/,$cmd);
  132.                 $cmd[1] = "-".$switch;
  133.                 $cmd = join(' ',@cmd);
  134.                 }
  135.                 $cmd = "/etc/uucp/"."$cmd $num";
  136.                 system("$cmd > /dev/null 2>&1");
  137.         }
  138.     } 
  139. }
  140.  
  141. sub deleteDevice {
  142.     $doRename = 0;
  143.     open(IN,"< $confD");
  144.     open(OUT,"> $dummy");
  145.     while(<IN>) {
  146.     @items = split(/\s+/);
  147.     if ($items[0] eq "ACU" && substr($items[1],4,1) eq $_[0]) {
  148.         $doRename = 1;
  149.         print OUT "# $_";
  150.     } elsif ($items[0] eq "Direct" && substr($items[1],4,1) eq $_[0]) {
  151.         $doRename = 1;
  152.         print OUT "# $_";
  153.     } else { print OUT $_; }
  154.     }
  155.     close(IN);
  156.     close(OUT);
  157.     if ($doRename) { rename($dummy,$confD); }
  158. }
  159.  
  160. sub editDevice {
  161.     $nm = $_[0];
  162.  
  163.     $found = 0;
  164.     open(IN,"< $confD");
  165.     open(OUT,"> $dummy");
  166.     while(<IN>) {
  167.     $line = $_;
  168.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  169.     $line =~ /^\s*(.*)$/;
  170.     $line1 = $1;
  171.     @items = split(/ /,$line1);
  172.     if ($items[0] eq "Direct" && $items[1] eq "ttyd".$nm) { 
  173.         print OUT "# $line";
  174.         if ($found == 0) {
  175.         $found = 1;
  176.         $mdm = &hash_modem($fld{'modem'.$nm},1,0);
  177.         if ($fld{'speed'.$nm} < 9600) { $dev = "ttym".$nm; }
  178.         else { $dev = "ttyf".$nm; }
  179.         print OUT "ACU $dev null $fld{'speed'.$nm} 212 x $mdm\n";
  180.         print OUT "Direct ttyd",$nm," - $fld{'speed'.$nm} direct\n";
  181.         }
  182.     } elsif ($items[0] eq "ACU" && substr($items[1],4,1) eq $nm) {
  183.         print OUT "# $line";
  184.     } else { print OUT $line; }
  185.     }
  186.     if ($found == 0) {
  187.     $mdm = &hash_modem($fld{'modem'.$nm},1,0);
  188.     if ($fld{'speed'.$nm} < 9600) { $dev = "ttym".$nm; }
  189.     else { $dev = "ttyf".$nm; }
  190.     print OUT "ACU $dev null $fld{'speed'.$nm} 212 x $mdm\n";
  191.     print OUT "Direct ttyd",$nm," - $fld{'speed'.$nm} direct\n";
  192.     }
  193.     close(OUT);
  194.     close(IN);
  195.     rename($dummy,$confD);
  196. }
  197.     
  198.  
  199. sub turnOffPort {
  200.     $nm = $_[0];
  201.     
  202.     open(IN,"< $confI");
  203.     open(OUT,"> $dummy");
  204.     while(<IN>) {
  205.     $line = $_;
  206.     if ($line =~ /^\s*\#/) { print OUT $line; next; }
  207.     $line =~ /^\s*(.*)$/;
  208.     $line1 = $1;
  209.     @items = split(/:/,$line1);
  210.     if ($items[0] eq "t".$nm) { 
  211.         splice(@items,2,1,"off");
  212.         $line = join(':',@items);
  213.         print OUT "$line\n"; 
  214.     }
  215.     else { print OUT $line; }
  216.     }
  217.     close(IN);
  218.     close(OUT);
  219.     rename($dummy,$confI);
  220. }
  221.  
  222. sub turnOnPort {
  223.     $nm = $_[0];
  224.     $found = 0;
  225.     open(IN,"< $confI");
  226.     open(OUT,"> $dummy");
  227.     while(<IN>) {
  228.         @items = split(/:/);
  229.         if ($items[0] eq "t".$nm) {
  230.             $iArg = &hash_modem($fld{'modem'.$nm},1,2);
  231.             print OUT "t$nm",":23:respawn:/usr/lib/uucp/uugetty ";
  232.             print OUT "-Nt60 -i$iArg",",conn ttyf$nm dx_38400\n";
  233.             $found = 1;
  234.         }
  235.         else { print OUT $_; }
  236.     }
  237.     if ($found == 0) {
  238.         $iArg = &hash_modem($fld{'modem'.$nm},1,2);
  239.         print OUT "t$nm:23:respawn:/usr/lib/uucp/uugetty ";
  240.         print OUT "-Nt60 -i$iArg ttyf$nm dx_38400\n";
  241.     }
  242.     close(IN);
  243.     close(OUT);
  244.     rename($dummy,$confI);
  245. }
  246.     
  247. sub getCurrentStatus {
  248.     $di[0] = 0; $di[1] = 0;
  249.     $do[0] = 0; $do[1] = 0;
  250.     open(IN,"< $confI");
  251.     while(<IN>) {
  252.     @items = split(/\s+/);
  253.     @terms = split(/:/,$items[0]);
  254.     if ($terms[0] eq "t1") {
  255.         if ($terms[2] ne "off") { 
  256.         $di[0] = 1;
  257.         $items[2] =~ /-i(.*)\,conn/;
  258.         $modem1 = &hash_modem($1,2,1); 
  259.         }
  260.     }
  261.     if ($terms[0] eq "t2") {
  262.         if ($terms[2] ne "off") { 
  263.         $di[1] = 1; 
  264.         $items[2] =~ /-i(.*)\,conn/;
  265.         $modem2 = &hash_modem($1,2,1); 
  266.         }
  267.     }
  268.     }
  269.     close(IN);
  270.  
  271.     open(IN,"< $confD");
  272.     while(<IN>) {
  273.     @items = split(/\s+/);
  274.     if ($items[0] eq "ACU") {
  275.         $char = substr($items[1],4,1);
  276.         if ($char eq "1") {
  277.         $do[0] = 1;
  278.         $modem1 = &hash_modem($items[6],0,1);
  279.         $speed1 = $items[3];
  280.         }
  281.         if ($char eq "2") {
  282.         $do[1] = 1;
  283.         $modem2 = &hash_modem($items[6],0,1);
  284.         $speed2 = $items[3];
  285.         }
  286.     }
  287.     }
  288.     close(IN);
  289.     
  290.     $val{'dial_in1'} = $di[0] ? 'Yes' : 'No';
  291.     $val{'dial_in2'} = $di[1] ? 'Yes' : 'No';
  292.     $val{'dial_out1'} = $do[0] ? 'Yes' : 'No';
  293.     $val{'dial_out2'} = $do[1] ? 'Yes' : 'No';
  294.  
  295.     if ($speed1 eq "") { $speed1 = "9600"; }
  296.     if ($speed2 eq "") { $speed2 = "9600"; }
  297.     if ($modem1 eq "") { $modem1 = "Hayes smartmodem"; }
  298.     if ($modem2 eq "") { $modem2 = "Hayes smartmodem"; }
  299.     
  300. sub generic {
  301.     print "<form name=StandardForm action=$myname method=post onSubmit=\"return
  302. runSubmit()\">";
  303.  
  304.     &header_block($title);
  305.  
  306.     print "<i>$message</i>";
  307.  
  308.     print "<center><table cellpadding=5 width=450>";
  309.  
  310.     print "<tr><th></th><th align=left>Port 1</th><th align=left>Port 2</th></tr>";
  311.  
  312.     print "<tr><th align=left>Reconfigure:</th><td align=left>",
  313.       &radio('enable1','No','Yes','No'),
  314.       "</td><td align=left>",
  315.       &radio('enable2','No','Yes','No'),"</td></tr>";
  316.  
  317.     print "<tr><th align=left>Allow users to dial in:<td align=left>",
  318.         &radio('dial_in1',$val{'dial_in1'},'Yes','No'),"</td><td>",
  319.         &radio('dial_in2',$val{'dial_in2'},'Yes','No'),"</td></tr>";
  320.  
  321.     print "<tr><th align=left>Allow users to dial out:<td align=left>",
  322.         &radio('dial_out1',$val{'dial_out1'},'Yes','No'),"</td><td>",
  323.         &radio('dial_out2',$val{'dial_out2'},'Yes','No'),"</td></tr>";
  324.  
  325.     print "<tr><th align=left>Modem model:</th><td align=left>",
  326.       &select_list('modem1',$modem1,*modemList), "</td>";
  327.  
  328.     print "<td align=left>",&select_list('modem2',$modem2,*modemList),"</td></tr>";
  329.  
  330.     print "<tr><th align=left>Baud rate:</th><td align=left>",
  331.       &select('speed1',$speed1,
  332.         '2400',
  333.         '9600',
  334.         '14400',
  335.         '19200',
  336.         '28800',
  337.         '38400'), "</td>";
  338.     print "<td align=left>",&select('speed2',$speed2,
  339.         '2400',
  340.         '9600',
  341.         '14400',
  342.         '19200',
  343.         '28800',
  344.         '38400'), "</td></tr>";
  345.  
  346.     print '</table></center><br>';
  347.  
  348.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"',
  349.         "onClick=\"do_help('$help_page'); return (false)\"");
  350.  
  351.     print '</form></body></html>';
  352. }
  353.  
  354.